var AddThis_Search = {

    init: function() {
        
        var kUrl = AddThis_Util.getStringPref("keyword.URL","");
        var sUrl = AddThis_Search.getUrl('ub');
        if (kUrl != sUrl && kUrl.indexOf(AddThis_Constants.SEARCH_SERVICE) != -1)
            AddThis_Util.setStringPref("keyword.URL", sUrl);
    },
	
	doSearch: function () {
		AddThis_Util.dbg("Search.doSearch: initting...");
		var text = document.getElementById("at_tbSearchTxt").value;
        if (text != "")
        {
    		var searchUrl = AddThis_Search.getUrl('tb') + encodeURIComponent(text);
    		AddThis_Util.dbg("Search.doSearch: searching '" + text + "', url: " + searchUrl);
            AddThis_Util.navToUrl(searchUrl);
        }
		AddThis_Util.dbg("Search.doSearch: done");
	},
    
    isVisible: function () {
        return ((AddThis_Util.getStringPref("browser.search.defaultenginename","") == AddThis_Constants.SEARCH_PLUGIN) &&
                (AddThis_Util.getStringPref("keyword.URL","").indexOf(AddThis_Constants.SEARCH_SERVICE) != -1));
    },
    
    getUrl: function(sl) {
        var url = AddThis_Constants.SEARCH_SERVICE +
            '?pco=' + AddThis_Constants.PCO + '-' + AddThis_Constants.EXTENSION_VERSION +
            '&locale=' + AddThis_Util.getLocale();
        if (typeof sl != 'undefined') url += '&sl=' + sl;
        url += '&q=';
        return url;
    }
};